package com.mc.moring.main.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mc.moring.R;
import com.mc.moring.bean.MyTradeListBean;
import com.mc.moring.main.MyTradesDetailsActivity;
import com.mc.moring.util.StringUtils;
import com.mc.moring.util.TimeUtils;


public class MyTradeAdapter extends BaseQuickAdapter<MyTradeListBean.dataBean, BaseViewHolder> {

    public MyTradeAdapter() {
        super(R.layout.item_my_trade);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyTradeListBean.dataBean item) {
        helper.setText(R.id.tv_transTime, TimeUtils.date2FormatDate(item.getTransTime()));
        helper.setText(R.id.tv_transAmount, "$"+ StringUtils.formatNumberWithCommas(item.getTransAmount()));
        helper.setText(R.id.tv_name, "$"+ StringUtils.formatNumberWithCommas(item.getTransAmount()));
        TextView tv_transStatus = helper.getView(R.id.tv_transStatus);
        if (item.getTransStatus().equals("S")) {
            tv_transStatus.setText("Éxito");
        } else if (item.getTransStatus().equals("F")) {
            tv_transStatus.setText("Fracaso");
        } else {
            tv_transStatus.setText("Procesando");
        }
        TextView tv_transType = helper.getView(R.id.tv_transType);
        if (item.getReqTransType().equals("OL")) {
            tv_transType.setText("Pago");
        } else if (item.getReqTransType().equals("LA")) {
            tv_transType.setText("Préstamo");
        }

        helper.getView(R.id.ll).setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putSerializable("_bean", item);
            Intent intent = new Intent();
            intent.setClass(mContext, MyTradesDetailsActivity.class);
            intent.putExtras(bundle);
            mContext.startActivity(intent);
        });
    }

}
